import os
import time
import unittest

import getpathInfo
from common.HTMLTestRunner import HTMLTestRunner
from testCase import test01case, test02case

path = getpathInfo.get_path()
report_path = os.path.join(path, 'result')

class AllTest():
    def __init__(self):
        global resultPath
        resultPath = os.path.join(report_path, "report.html")  # result/report.html
        self.caseListFile = os.path.join(path, "caselist.txt")  # 配置执行哪些测试文件的配置文件路径
        self.caseFile = os.path.join(path, "testCase")  # 真正的测试断言文件路径
        self.caseList = []

    def set_case_list(self):
        fb = open(self.caseListFile)
        for value in fb.readlines():
            data = str(value)
            if data != '' and not data.startswith('#'):
                self.caseList.append(data.replace('\n',''))
        fb.close()

    def run(self):
        """
        :return:
        """
        ut = unittest.TestSuite()
        f = open(self.caseListFile)
        lines = f.readlines()
        print(lines)
        for x in lines:
            print("test02case： "+ x[:-1])
            ut.addTest(test02case.testwitwork(x[:-1]))
        basedir = getpathInfo.get_path()
        path = basedir + '\\result\\'
        now = time.strftime("%Y%m%d-%H%M")
        file_path = path + now +'-report.html'
        fp = open(file_path,"wb")
        runner = HTMLTestRunner(stream=fp,
                                title="API测试报告",
                                description="登录接口")
        runner.run(ut)
        fp.close()
if __name__ == '__main__':
    AllTest().run()